#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include <string.h>
#include "dominion/dominion.h"
#include "dominion/dominion_helpers.h"
#include "dominion/rngs.h"
#include "dominion/interface.h"

/* testing buyCard() */

int buyCard(int supplyPos, struct gameState *state);

int main(int argc, char *argv[])
{
	/*modified from the initialization in the provided testUpdateCoins.c file */
    int seed = 1000;
    int numPlayer = 2;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
	int r;
	
	/* test one -- to see if proper count amount deducted after buying card */
   	struct gameState test_one;
    memset(&test_one, 23, sizeof(struct gameState));   // clear the game state
    r = initializeGame(numPlayer, k, seed, &test_one); // initialize a new game
	
	test_one.coins = 6;
	buyCard(adventurer, &test_one);
	
	if (test_one.coins == 0)
		printf("buyCard(): PASS when buying the Adventurer card, removes 6 coins.\n");
	else
		printf("buyCard(): FAIL when buying the Adventurer card, did not remove 6 coins.\n");
	
	/* test two -- to see if numBuys is decremented after purchasing a card */
   	struct gameState test_two;
    memset(&test_two, 23, sizeof(struct gameState));   // clear the game state
    r = initializeGame(numPlayer, k, seed, &test_two); // initialize a new game
	
	test_two.coins = 3;
	test_two.whoseTurn = 1;
	test_two.numBuys = 1;
	buyCard(village, &test_two);
	if (test_two.numBuys == 0)
		printf("buyCard(): PASS when testing numBuys, which started at 1 and become 0 after buyCard().\n");
	else
		printf("buyCard(): FAIL when testing numBuys, which started at 1 and did not become 0 after buyCard().\n");
	
	/* test three -- to see if the player's handCount is incremented after purchasing */
   	struct gameState test_three;
    memset(&test_three, 23, sizeof(struct gameState));   // clear the game state
    r = initializeGame(numPlayer, k, seed, &test_three); // initialize a new game
	
	test_three.coins = 4;
	test_three.whoseTurn = 0;
	int current_deck_count = test_three.deckCount[0];
	buyCard(feast, &test_three);
	if (test_three.deckCount[0] == current_deck_count + 1)
		printf("buyCard(): PASS when testing deck count, which should be 1 more for the player after buyCard().\n");
	else
		printf("buyCard(): FAIL when testing deck count, which should be 1 more for the player after buyCard(), but was not.\n");
	
	/* test four -- a boundary case to see if coins are NOT deducted when attempting to purchae a card that the player
	does not have enough money to purchase */
   	struct gameState test_four;
    memset(&test_four, 23, sizeof(struct gameState));   // clear the game state
    r = initializeGame(numPlayer, k, seed, &test_four); // initialize a new game
	
	test_four.coins = 2;
	test_four.whoseTurn = 1;
	buyCard(council_room, &test_four);
	if (test_four.coins == 2)
		printf("buyCard(): PASS when testing boundary case, number of coins the same after attempting to purchase a card that is too expensive.\n");
	else
		printf("buyCard(): FAIL when testing boundary case, number of coins NOT the same after attempting to purchase a card that is too expensive. \n");
		
	
    return 0;
}
